package com.tencent.sr.iris.baisc.saas.export.sdk;

import com.tencent.sr.rmall.material.utils.CosSdkService;
import java.io.File;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

@Component
@ConditionalOnProperty(
    name = {"tjob.isActive"},
    havingValue = "true"
)
@Slf4j
public class CosDependency {
    @Resource
    private CosSdkService cosSdkService;
    @Value("${cosPrivate.bucket}")
    private String bucket;

    public CosDependency() {
    }

    public String upload(String key, File file) {
        try {
            String url = this.cosSdkService.uploadFile(this.bucket, key, file);
            log.info("上传文件成功 url = {}", url);
            return url;
        } catch (Exception var4) {
            log.error("上传文件异常");
            return null;
        }
    }
}